<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\App;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AppController extends AdminController
{
    protected $title = '应用管理';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new App(), function (Grid $grid) {
           // $grid->column('id')->sortable();
            $grid->column('name','应用名');
            $grid->column('icon','图标')->image();
            //$grid->column('d','下载地址');
            $grid->column('s','排序');
            $grid->column('ext','版本');
            $grid->column('created_at','添加时间');
            $grid->model()->orderBy('id', 'desc');
          //  $grid->column('updated_at')->sortable();
            $grid->model()->orderBy('s','asc');
            $grid->disableBatchDelete();
            $grid->disableRefreshButton();
            $grid->disableRowSelector();
            $grid->disableViewButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('name','应用名');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new App(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('icon');
            $show->field('d');
            $show->field('s');
  
            $show->field('ext','渠道');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new App(), function (Form $form) {
            $form->display('id');
            $form->text('name','应用名');
            $form->image('icon','图标');
            $form->text('d','下载地址');
            $form->number('s','排序');
            $form->text('ext','版本');
            $form->display('created_at');
            $form->display('updated_at');
       
            $form->footer(function ($footer) {
                $footer->disableViewCheck();
                $footer->disableReset();

                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();

                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
        });
        });
    }
}
